package com.bifrost.web.controller;

import com.bifrost.annotation.Authorization;
import com.bifrost.annotation.CurrentStore;
import com.bifrost.entity.MerchantStore;
import com.bifrost.entity.SystemHelpcenter;
import com.bifrost.common.model.ResultModel;
import com.bifrost.service.StoreService;
import com.bifrost.service.SystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author rangf
 * @date 2018/1/17
 */
@Api("系统接口")
@RestController
@RequestMapping("/api/system")
public class SystemController {

    @Autowired
    SystemService systemService;
    @Autowired
    StoreService storeService;

    @ApiOperation("获取系统帮助中心")
    @ApiImplicitParam(paramType = "query", name = "helpId", value = "helpId", required = true, dataType = "Long")
    @GetMapping("/help/{helpId}")
    public ResultModel getHelp(@PathVariable Long helpId) {
        SystemHelpcenter systemHelpcenter = systemService.getSystemHelp(helpId);
        String contents = null;
        if (systemHelpcenter != null) {
            contents = systemHelpcenter.getHelpcenterContent();
        }
        return ResultModel.ok().put("contents", contents);
    }

    @ApiOperation("获取系统帮助中心")
    @ApiImplicitParam(paramType = "query", name = "helpId", value = "helpId", required = true, dataType = "Long")
    @Authorization
    @GetMapping("/help")
    public ResultModel getHelp(@CurrentStore Long storeId,@RequestParam String code) {
        MerchantStore store = storeService.getMerchantStore(storeId);
        SystemHelpcenter systemHelpcenter = systemService.getSystemHelp(store,code);
        String contents = null;
        if (systemHelpcenter != null) {
            contents = systemHelpcenter.getHelpcenterContent();
        }
        return ResultModel.ok().put("contents", contents);
    }
}
